package cn._2dland.leech.clients;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.NameValuePair;

import cn._2dland.leech.LeechClient;

/**
 * A leech client use h-leech.com
 * @author deadblue
 */
public class HLeechClient extends LeechClient {

	@Override
	protected String getParseURL(String url) {
		return "http://178.162.229.204/~hleech/index.php";
	}

	@Override
	protected String getParseReferer(String url) {
		return "http://h-leech.com/";
	}

	@Override
	protected NameValuePair[] getParseParams(String url) {
		NameValuePair[] params = {
				new NameValuePair("link", url),
				new NameValuePair("add_comment", "on"),
				new NameValuePair("comment", "fs"),
				new NameValuePair("premium_acc", "on"),
				new NameValuePair("premium_user", ""),
				new NameValuePair("premium_pass", "")
		};
		return params;
	}

	@Override
	protected String getTransloadURL(String url) {
		return "http://178.162.229.204/~hleech/index.php";
	}

	@Override
	protected String parseDownloadURL(String url, String body) {
		String downURL = null;

		Matcher m = Pattern.compile("<a href=\"/~hleech/files/[^\"]+\"").matcher(body);
		if(m.find()) {
			downURL = body.substring(m.start() + 9, m.end() - 1);
			downURL = "http://178.162.229.204" + downURL;
		}

		return downURL;
	}

}
